SHELL := /bin/sh

.SUFFIXES: .cpp .o

SRCDIR := src
BINDIR := .
BUILDDIR := build

CX := g++ -ggdb
CFLAGS := -O2 -fpermissive -msse2 `sdl-config --cflags` `corona-config --cxxflags` `xml2-config --cflags` -I/usr/lib/libxml++-2.6/include/ -I/usr/include/libxml++-2.6 -I/usr/lib/glibmm-2.4/include/ -I/usr/include/glibmm-2.4 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include `python-config --includes` -I/usr/local/include/bullet

LIBS := `sdl-config --libs` -lSDL_mixer -lSDL_net -lGL -lGLU -lCg -lCgGL `corona-config --libs` `xml2-config --libs` -lboost_date_time -lboost_thread -lboost_system -lxml++-2.6 `python-config --libs` -lboost_python `icu-config --ldflags` -lxerces-c `openal-config --libs` -lalut

BULLET_LIBS := -rdynamic -L/usr/local/lib -lbulletdynamics -lbulletcollision -lbulletmath -lbulletsoftbody

CXXFILES := $(shell find $(SRCDIR) -name "*.cpp")
OBJFILES := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(CXXFILES))
DEPFILES := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(CXXFILES))

BINNAME = wtf08

all: $(BINDIR)/$(BINNAME) Makefile

-include $(DEPFILES)

tags:
	./build_tags.sh

clean: 
	rm -v $(BUILDDIR)/*.o $(BUILDDIR)/*.d

test: $(BINDIR)/$(BINNAME)
	@($(BINDIR)/$(BINNAME))

$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
	@(echo " --- CXX --- $<")
	@($(CX) $(CFLAGS) -MMD -MP -MT "$(BUILDDIR)/$*.d" -c $< -o $(BUILDDIR)/$*.o)

$(BINDIR)/$(BINNAME): $(OBJFILES)
	@(echo " --- LD --- $(BINNAME)")
	@(c++ -ggdb $(LIBS) $(OBJFILES) -o $(BINDIR)/$(BINNAME) $(BULLET_LIBS))

